package com.qzsoft.zhjd.asphalt.modules.asphaltmatch.service.impl;

import com.qzsoft.zhjd.asphalt.modules.asphaltmatch.entity.AsphaltMatchColdEntity;
import com.qzsoft.zhjd.asphalt.modules.asphaltmatch.mapper.AsphaltMatchColdMapper;
import com.qzsoft.zhjd.asphalt.modules.asphaltmatch.service.AsphaltMatchColdService;
import com.qzsoft.zhjd.asphalt.modules.asphaltmatch.service.AsphaltMatchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

/**
 * @ClassName AsphaltMatchColdServiceImpl
 * @Description 沥青混合料冷料配比数据
 * @author linhuawei
 * @since 2021-12-06
 */
@Service
public class AsphaltMatchColdServiceImpl extends ServiceImpl<AsphaltMatchColdMapper, AsphaltMatchColdEntity>
        implements AsphaltMatchColdService {

    @Autowired
    private AsphaltMatchService asphaltMatchService;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean save(AsphaltMatchColdEntity entity) {
        // 判断冷料配置是否存在
        AsphaltMatchColdEntity temp = baseMapper.selectById(entity.getId());
        if (null == temp) {
            baseMapper.insert(entity);
        } else {
            baseMapper.updateById(entity);
        }

        // 更新配比冷料配置状态
        asphaltMatchService.updateColdConfig(entity.getId(), 1);
        return true;
    }

}
